<!-- 数据字典选择下拉 -->
<template>
	<view class="">
		<view class="">
			<u-radio-group
			    v-model="radiovalue"
				:disabled="disabled"
			  >
			    <u-radio
			      :customStyle="{marginRight: '30rpx'}"
			      v-for="(item, index) in listByCodes"
			      :key="index"
			      :label="item.title"
			      :name="item.value"
			      @change="radioChange"
			    >
			    </u-radio>
			  </u-radio-group>
		</view>
	</view>
</template>

<script>
	import { initDictOptions } from '@/utils/JDictSelectUtil.js'
	
	export default {
		name: 'hDictRadio',
		data() {
			return {
				radiovalue: '', // 选中的值
				listByCodes: [], // 字典列表
			}
		},
		model: {
			prop: 'value',
			event: 'change',
		},
		props: {
			// 字典编号
			dictName: {
				type: String,
				default: ''
			},
			// 是否禁用
			disabled: {
				type: Boolean,
				default: false
			},
			// 选中的值
			value: {
				type: [String, Number],
				default: '',
			},
		},
		watch: {
			dictName: {
				handler (val) {
					if (val) {
						this.queryDictModelByCodes(val)
					}
				},
				immediate: true
			},
			// 监听哪个有值就先走哪个保证能回显title
			value: {
				handler (val) {
					if (val || val == 0) {
						this.radiovalue = val + ''
					}
				},
				immediate: true
			},
		},
		methods: {
			//字典
			queryDictModelByCodes(name) {
				initDictOptions(name).then(res => {
					if (res.success) {
						this.listByCodes = res.result
					}
				}).catch(err => {
				})
			},
			
			radioChange(n) {
				this.$emit('change', n)
				this.$emit('input', n)
			}
			
			// 选择生产状态
			// codesClick (check,index) {
			// 	if(!check) {
			// 		this.listByCodes[this.oldzgqkindex].check = false
			// 		this.listByCodes[index].check = true
			// 		// this.form.sczt = this.listByCodes[index].value
			// 		this.$emit('codesClick', this.listByCodes[index].value)
			// 	} else {
			// 		this.listByCodes[index].check = false
			// 		this.$emit('codesClick', '')
			// 	}
			// 	this.oldzgqkindex = index
			// },
		},
		mounted() {
			//初始化数据
			this.queryDictModelByCodes(this.dictName);
		},
	}
</script>

<style lang="scss" scoped>
	
</style>